//
// Created by francklinson on 2021/8/29 AT 0:11.
//
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <algorithm>
#include <functional>
#include <climits>

using namespace std;

class Solution {
public:
    int sumOddLengthSubarrays(vector<int> &arr) {
        vector<int> preSum = {0};
        for (int e: arr) preSum.push_back(preSum.back() + e); // 前缀和
        int res = 0;
        for (int i = 0; i < arr.size(); i++)
            for (int sz = 1; i + sz - 1 < arr.size(); sz += 2)  // 奇数长度
                res += preSum[i + sz] - preSum[i];
        return res;
    }

};

int main() {
    vector<int> arr{1, 4, 2, 5, 3};
    auto solution = new Solution;
    cout << solution->sumOddLengthSubarrays(arr) << endl;
    delete solution;
    solution = nullptr;
    return 0;
}

